using System.Collections;
using System.Collections.Generic;
using Script.My_Gameplay_Ability_System.Attributes.Base;
using Script.My_Gameplay_Ability_System.Attributes.Components;
using UnityEngine;

namespace Script.My_Gameplay_Ability_System.Attributes.Derived
{
    /// <summary>
    /// 线性派生属性
    /// </summary>
    public class LinearDerivedAttribute : AttributeBase
    {
        /// <summary>
        /// 基础属性
        /// </summary>
        public AttributeBase Attribute { get; set; }
        /// <summary>
        /// 斜率
        /// </summary>
        private float gradient;
        /// <summary>
        /// 截距
        /// </summary>
        private float offset;

        /// <summary>
        /// 计算线性依赖属性的属性值(重写，单一依赖)
        /// </summary>
        /// <param name="attributeValue">依赖属性值</param>
        /// <param name="otherAttributeValues">所有基础属性值</param>
        /// <returns>线性依赖属性值</returns>
        public override AttributeValue CalculateCurrentAttributeValue(AttributeValue attributeValue, List<AttributeValue> otherAttributeValues)
        {
            // 查找依赖属性值所依赖的基础属性
            var baseAttributeValue = otherAttributeValues.Find(x => x.Attribute == this.Attribute);

            // 根据基础属性值计算当前依赖属性值
            attributeValue.BaseValue = (baseAttributeValue.CurrentValue * gradient) + offset;

            attributeValue.CurrentValue = (attributeValue.BaseValue + attributeValue.Modifier.Add) * (attributeValue.Modifier.Multiply + 1);

            if (attributeValue.Modifier.Override != 0)
            {
                attributeValue.CurrentValue = attributeValue.Modifier.Override;
            }
            return attributeValue;
        }
    }
}


